package com.base.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.base.domain.SysUser;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author gxd
 * @since 2025/6/6
 */
public interface SysUserMapper extends BaseMapper<SysUser> {

    /**
     * 分页列表
     * @param user 用户
     * @return 用户列表
     */
    @Select("<script> " +
            "SELECT t1.dept_name, t2.* " +
            "FROM sys_dept t1 " +
            "JOIN sys_user t2 ON t1.id = t2.dept_id " +
            "where " +
            "   t2.deleted = 0 " +
            "   <if test=\"user.deptId != null and user.deptId != 0\"> " +
            "       AND t2.dept_id = #{user.deptId}" +
            "   </if> " +
            "   <if test=\"user.username != null and user.username != ''\"> " +
            "       AND t2.username LIKE concat('%', #{user.username}, '%') " +
            "   </if> " +
            "   <if test=\"user.phone != null and user.phone != ''\"> " +
            "       AND t2.phone LIKE concat('%', #{user.phone}, '%') " +
            "   </if> " +
            "   <if test=\"user.status != null\"> " +
            "       AND t2.status = #{user.status}" +
            "   </if> " +
            "   <if test=\"user.startTime != null and user.startTime != ''\"> " +
            "       AND date_format(t2.create_time, '%Y%M%d') &gt;= date_format(#{user.startTime}, '%Y%M%d')" +
            "   </if> " +
            "   <if test=\"user.endTime != null and user.endTime != ''\"> " +
            "       AND date_format(t2.create_time, '%Y%M%d') &lt;= date_format(#{user.endTime}, '%Y%M%d')" +
            "   </if> " +
            "</script> ")
    List<SysUser> pageList(@Param("user") SysUser user);
}
